export function getHashParams(url?: string) {
  return new URLSearchParams(new URL(url || location.href).hash.substring(1));
}

export function setHashParams(params: URLSearchParams, replace = false) {
  const hash = params.toString();
  const oldURL = new URL(location.href);
  const newURL = new URL(location.href);
  newURL.hash = hash;

  history[replace ? 'replaceState' : 'pushState'](null, '', newURL.toString());
  const hashChangeEvent = new HashChangeEvent('hashchange', {
    oldURL: oldURL.toString(),
    newURL: newURL.toString(),
  });
  window.dispatchEvent(hashChangeEvent);
}
